package com.zyb.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;
import javax.swing.plaf.TextUI;

import org.springframework.stereotype.Service;

import com.zyb.dao.MessageDao;
import com.zyb.pojo.Message;
import com.zyb.service.MessageService;
import com.zyb.util.FormatUtil;
import com.zyb.util.TextUtil;


@Service("MessageService")
public class MessageServiceImpl implements MessageService {

	@Resource(name="MessageDao")
	private MessageDao messageDao;
	
	@Override
	public String saveMessage(Message message) {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateNowStr = sdf.format(date);
		message.setDate(dateNowStr);
		
		/*if (!FormatUtil.isName(message.getName())) {
			return "姓名不合规范";
		}*/
		if (TextUtil.isEmpty(message.getName())) {
			return"姓名不能为空";
		}
		
		if(!FormatUtil.isMobileNum(message.getPhone())) {
			return "手机号码不合规范";
		}
		
		if(TextUtil.isEmpty(message.getMsg())) {
			return "内容不能为空";
		}
		
		messageDao.saveMessage(message);
		return "留言成功";
	}

}
